#ifndef WEATHERTRAYICON_H
#define WEATHERTRAYICON_H

#include <QObject>
#include <QSystemTrayIcon>
#include <QNetworkReply>
#include <QAction>
#include <QMenu>
#include <QNetworkAccessManager>
#include <QCache>

class WeatherTrayIcon : public QSystemTrayIcon
{
    Q_OBJECT
public:
    explicit WeatherTrayIcon();

private slots:
    void requestXml();
    void readXml(QNetworkReply* reply);
    void readIcon(QNetworkReply* reply);
    void setCity(QAction* action);

private:
    QMenu menu;
    QNetworkAccessManager* networkXmlAccess;
    QNetworkAccessManager* networkIconAccess;
    QString city;
    QCache<QUrl, QIcon> iconCache;
    int retryDelaySec;

private:
    void createContextMenu();
    void populateToolTip(QString data);
    QString textForTag(QString tag, QString data);
    QString toolTipField(const QString& name, const QString& color, const QString& value, bool appendBr=false);
};

#endif // WEATHERTRAYICON_H
